///==================================================================================
///全局函数扩展
///==================================================================================
(function(){
//重复n次字符串,此方法相当于vbscript中的string()函数
String.prototype.string = function(n)
{
    var s = "";
    for( var i=0; i<n; i++ ){  s = s + this;    }
    return s;
};

//相当于c#的string.Format函数
String.prototype.format = function()
{
    var args = arguments;
    return this.replace(/\{(\d+)\}/g,
        function(m,i){
            return args[i];
        });
}

})();


// 选中文本
function selectItem(obj){
    //var obj = document.getElementsByName("textRange")[0];
    var range = obj.createTextRange();
    range.moveStart("character",0);
    range.select();
}


///==================================================================================
///jQuery扩展
///==================================================================================

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true});
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


/**
 * html编码
 */
jQuery.htmlEncode = function (html)
{
    var temp = document.createElement ("div");
    (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
    var output = temp.innerHTML;
    temp = null;
    return output;
};

/**
 * html解码
 */
jQuery.htmlDecode = function (text)
{
    var temp = document.createElement("div");
    temp.innerHTML = text;
    var output = temp.innerText || temp.textContent;
    temp = null;
    return output;
};

/**
 * 字符串转换成NameValueCollection
 */
jQuery.toNameValueCollection = function(text)
{
    var nvc = new Array();
    var arr = $.trim(text).split('&');
    for( var i=0,len=arr.length;i<len;i++ ){
        var nv = arr[i].split('=');
        nvc[nv[0]] = nv[1];
    }

    nvc.toString = function( separator )
    {
        var arr = new Array();
        for( var key in this ){
            if( "toString" != key ){
                arr.push( key.concat("=",this[key]) );
            }
        }
        if( 'undefined' == typeof(separator) ){
            return arr.join( "&" );
        }else{
            return arr.join( separator );
        }
    }
    return nvc;
};

/**
 * 分页导航样式
 */
jQuery.pageNav = function( recordCount, pageCount, curPage, cmd )
{
    if( String == cmd.constructor ){
        cmd = $.trim(cmd).replace("#","");
        cmd = $.toNameValueCollection(cmd);
    }

    // 检查数据类型
    recordCount = parseInt( recordCount );
    pageCount = parseInt( pageCount );
    curPage = parseInt( curPage );

    // 限定页数在有效的范围
    if ( 1 > curPage ){ curPage = 1;  }
    if ( pageCount < curPage ){ curPage = pageCount;  }

    var startNum,endNum;
    //开始 页码
    if ( 10 >= curPage ){ startNum = 1;   }
    else                { startNum = curPage - 10;  }

    //结束 页码
    endNum = curPage + 10;
    if( endNum > pageCount ){ endNum = pageCount;   }

    var s = "<div>";
    // 上一页
    if( 1 < curPage ){
        cmd["page"] = curPage-1;
        s += '<a href="#' + cmd.toString() + '">上一页</a>';
    }

    // 页连接列表
    for( var i = startNum; i <= endNum; i++ )
    {
        if( i == curPage ){
            s += " " + i + " ";    }
        else{
            cmd["page"] = i;
            s += '<a href="#' + cmd.toString() + '">[' + i + ']</a>';
        }
    }

    // 下一页
    if( curPage < pageCount){
        cmd["page"] = curPage+1;
        s += '<a href="#' + cmd.toString() + '">下一页</a>';    }

    s += "</div>";
    // 记录总数
    s += "<div>共找到记录 " + recordCount + " 篇</div>";

    return s;
};

// 按日期生成一个唯一的ID
jQuery.newId = function()
{
    var d = new Date();
    return d.getFullYear().toString()+(d.getMonth()+1).toString()+d.getDate().toString()
        +d.getHours().toString()+d.getMinutes().toString()+d.getSeconds().toString()
        +d.getMilliseconds()+Math.floor(Math.random()*1000).toString();
};

// 转换QueryString为Json对象
jQuery.toJson=function(s, overwrite){ 
    var obj = {}, 
    pairs = s.split('&'), 
    d = decodeURIComponent, 
    name, 
    value; 
    $.each(pairs, function(i,pair) { 
        pair = pair.split('='); 
        name = d(pair[0]); 
        value = d(pair[1]); 
        obj[name] = overwrite || !obj[name] ? value : 
        [].concat(obj[name]).concat(value); 
    });
    return obj; 
}; 

//转换Json对象为QueryString
jQuery.toString=function(o, pre){ 
    var undef, buf = [], key, e = encodeURIComponent; 
    for(key in o){ 
        undef = o[key]== 'undefined'; 
        $.each(undef ? key : o[key], function(val, i){ 
            buf.push("&", e(key), "=", (val != key || !undef) ? e(val) : ""); 
        }); 
    } 
    if(!pre){ 
        buf.shift(); 
        pre = ""; 
    } 
    return pre + buf.join(''); 
}; 
///==================================================================================
///jQuery.fn扩展
///==================================================================================

(function( $ ){

    jQuery.fn.extend({
        /**
         * jQuery1.3以后的功能
         * 寻找符合表达式的第一个祖先节点
         */
        closest : function(exp)
        {
            var p = $(this).parent(exp);
            if( p )
                return p;
            else
                return p.closest(exp);
        },
        /**
         * 创建遮蔽层
         */
        openMask : function()
        {
            var w = $(this).width();
            var h = $(this).height();
            
            if(!this.m)
            {this.m = $('<div></div>');}
            
            this.m.css({position:'absolute',left:'0',top:'0',width:w+'px',height:h+'px',background:'#999',filter:'alpha(opacity=0)',opacity:'0'});
            $(this).append(this.m);
            this.m.fadeTo('normal',0.66);
            return this.m;
        },
        /**
         * 关闭遮蔽层
         * 控制对象应该是一个由openMask返回的遮罩对象
         */
        closeMask : function()
        {
            $(this).fadeOut('normal');
        },
        /**
         * 弹出警告(提示)
         */
        alert : function(content,title)
        {
            title = title || '提示';
            var d = new jqDialog({title:title,content:content});
            
            var foot = $('<div></div>');
            var btn = $('<input type="button" value="关闭" />');
            foot.append(btn)
                .appendTo(d.wrap)
                .css({'text-align':'right'});
            
            d.open($(this));
            
            btn.click(function(){d.close()});
        },
        /**
         *  弹出确认框
         */
        confirm : function(title,content,callbackY,callbackN)
        {
            title = title || '确认';
            var d = new jqDialog({title:title,content:content});
            
            var foot = $('<div></div>');
            var btnY = $('<button>是</button>');
            var btnN = $('<input type="button" value="否" />');
            foot.append(btnY)
                .append(btnN)
                .appendTo(d.wrap)
                .css({'text-align':'right'});
            
            d.open($(this));

            btnY.click(function(){
                if( callbackY ) callbackY();
                d.close();
            });
            btnN.click(function(){
                if( callbackN ) callbackN();
                d.close();
            });
        },
        /**
         *
         */
        Dialog : function(id,prop,callback)
        {
            var d = jqDialog.getInstance(id,prop);
            d.open($(this),callback);
            
        },
        /**
         * ajaxSubmit,支持三种重载类型
         *  1. dataType表示返回数据的格式
         *  2. callback(string),string由ajaxSubmit填充
         *  3. dataType,callback
         */
        ajaxSubmit : function()
        {
            var dataType = 'json';  //默认返回数据类型
            var callback = null;   //默认回调函数
            
            if( 1==arguments.length ){     //设定重载参数,一个参数时
                if( String==arguments[0].constructor )
                    dataType = arguments[0];
                else
                    callback = arguments[0];
            }
            
            if( 2==arguments.length ){      //设定重载参数,两个参数时
                dataType = arguments[0];
                callback = arguments[1];
            }
            
            /// $(this).unbind("submit");   //防止多次调用本函数时造成的多次绑定
            $(this).submit( function(){
                var fields = $.toJson( $(this).serialize() );  // 本次上传的数据,供回调函数使用
                $.ajax({
                    async: false,
                    cache: false,
                    timeout: 20000,
                    type: "POST",
                    contentType:"application/x-www-form-urlencoded",
        
                    url: $(this).attr("action"),
                    data:$(this).serialize(),
                    dataType: dataType,
        
                    //complete:function(dat){alert(dat);},
                    success:function(dat){
                        if(null==callback)
                            alert(dat);
                        else
                            callback( dat,fields );
                    },
                    error: function(dat){
                        alert(dat);
                    }
                });
                return false;
            });
        },
        
        /**
         * fckEditor
         */
        fckHtmlEditor : function( basePath, height, toolbarSet )
        {
            // fckEditor
            var oFCKeditor = new FCKeditor( $(this)[0].name );
            oFCKeditor.BasePath = basePath || "fckeditor/";
            oFCKeditor.Height = height || 400;
            oFCKeditor.ToolbarSet = toolbarSet || "Default";
            oFCKeditor.ReplaceTextarea();
        },
        
        /**
         * 清空select, 此段代码抄自 jQuery in action
         */
        emptySelect : function()
        {
            return this.each(function(){
                if(this.tagName=='SELECT'){ this.options.length = 0; }
            });
        },
        /**
         * 载入select, 此段代码抄自 jQuery in action
         */
        loadSelect : function(optionsDataArray)
        {
            return this.emptySelect().each(function(){
                if(this.tagName=='SELECT'){
                    var selectElement = this;
                    $.each(optionsDataArray, function(index,optionData)
                    {
                        var option = new Option(optionData.caption,optionData.value);
                        if($.browser.msie){
                            selectElement.add(option);
                        }
                        else{
                            selectElement.add(option,null);
                        }
                    });
                }
            });
        }
    });


})(jQuery);



///==================================================================================
///历史管理类
///==================================================================================
(function(){
/**
 * HistoryStack
 *
 * A JavaScript object for storing resources or identifiers in a
 * history stack.  The history lasts as long as the browser is
 * open (i.e. session cookie).
 *
 * Written by Mike Brittain for IBM developerWorks.
 */

/**
 * Constructor
 */
var HistoryStack = window.HistoryStack = function()
{
    /** Current stack loaded in memory, which will also be
        cached to cookies. */
    this.stack = new Array();

    /** Pointer to current location in the history stack. */
    this.current = -1;

    /** Max size of the history stack. */
    this.stack_limit = 15;
}


/**
 * Return the name of the current resource in the
 * history stack.
 */
HistoryStack.prototype.getCurrent = function ()
{
    return this.stack[this.current];
};

/**
 * Add the resource to the next position after the "current" pointer.
 * If there are items existing past current, they will first be cut
 * off the end of the stack.  The stack will also be truncated to
 * "stack_limit" if it has grown to large.
 */
HistoryStack.prototype.addResource = function(resource)
{
    if (this.stack.length > 0) {
        this.stack = this.stack.slice(0, this.current + 1);
    }
    this.stack.push(resource);
    while (this.stack.length > this.stack_limit) {
        this.stack.shift();
    }
    this.current = this.stack.length - 1;
    this.save();
};


/**
 * Handle navigation within the history stack.  Any negative argument
 * will go backwards in the stack and positive arguments will go
 * forward.  If zero is passed to the method, the page will be
 * reloaded.
 */
HistoryStack.prototype.go = function(increment)
{
    // Go back...
    if (increment < 0) {
        this.current = Math.max(0, this.current + increment);

    // Go forward...
    } else if (increment > 0) {
        this.current = Math.min(this.stack.length - 1,
                                this.current + increment);

    // Reload...
    } else {
        location.reload();
    }

    this.save();
};


/**
 * Returns boolean value whether there is a previous
 * entry in the history stack.
 */
HistoryStack.prototype.hasPrev = function()
{
    return (this.current > 0);
};

/**
 * Returns boolean value whether there is a suceeding
 * entry in the history stack.
 */
HistoryStack.prototype.hasNext = function()
{
    return (this.current < this.stack.length - 1
            && this.current > -1);
};


/**
 * Save the current history stack and pointer to cookies
 */
HistoryStack.prototype.save = function()
{
    this.setCookie('CHStack', this.stack.toString());
    this.setCookie('CHCurrent', this.current);
};

/**
 * Load the history stack and pointer from cookies.
 */
HistoryStack.prototype.load = function()
{
    var tmp_stack = this.getCookie('CHStack');
    if (tmp_stack != '') {
        this.stack = tmp_stack.split(',');
    }

    var tmp_current = parseInt(this.getCookie('CHCurrent'));
    if (tmp_current >= -1) {
        this.current = tmp_current;
    }
};



/**
 * Save a name/value pair as a browser cookie, to expire at
 * end of session.
 */
HistoryStack.prototype.setCookie = function(name, value)
{
    var cookie_str = name + "=" + escape(value);
    document.cookie = cookie_str;
};

/**
 * Retrieve a cookie value by the given name.
 */
HistoryStack.prototype.getCookie = function(name)
{
    if (!name) return '';

  var raw_cookies, tmp, i;
  var cookies = new Array();

  raw_cookies = document.cookie.split('; ');
  for (i=0; i < raw_cookies.length; i++) {
    tmp = raw_cookies[i].split('=');
    cookies[tmp[0]] = unescape(tmp[1]);
  }

  if (cookies[name] != null) {
    return cookies[name];
  } else {
    return '';
  }
};


})();


///==================================================================================
///来源于《Javascript设计模式》的代码
///==================================================================================

// Constructor.
var Interface = function(name,methods){
    if(arguments.length != 2 ){
        throw new Error("Interface constructor called with " + arguments.length
            + "arguments, but expected exactly 2.");
    }

    this.name = name;
    this.methods = [];
    for( var i=0,len=methods.length; i<len; i++ ){
        if( typeof methods[i] !== 'string' ){
            throw new Error("Interface constructor expects method names to be passed in as a string.");
        }
        this.methods.push(methods[i]);
    }
};

// Static class method.
Interface.ensureImplements = function(object){
    if( arguments.length<2 ){
        throw new Error("Function Interface.ensureImplements called with "
            + arguments.length + " arguments, but expected at least 2.");
    }
    
    for( var i=1,len=arguments.length; i<len; i++ ){
        var interface = arguments[i];
        if(interface.constructor !== Interface ){
            throw new Error("Function Interface.ensureImplements expects arguments two and above to be instances of Interface.");
        }
        
        for( var j=0,methodsLen=interface.methods.length; j<methodsLen; j++ ){
            var method = interface.methods[j];
            if( !object[method]||typeof object[method]!=='function' ){
                throw new Error("Function Interface.ensureImplements: object does not implement the "
                    + interface.name + " interface. Method " + method + " was not found.");
            }
        }
    }
};



///==================================================================================
/// jqTabs
///==================================================================================
//css
//        /*同时，我们有以下的css类定义：*/
//        .ui-tabs-nav{
//            /*导航容器定义*/
//        }

//        .ui-tabs-selected{
//            /*激活的标签样式*/
//        }
//        .ui-tabs-panel{
//            /*默认的显示区域样式*/
//        }
//        .ui-tabs-hide{
//            display: none;
//        }
//
//html
//        <!--与此对应的HTML结构是：-->
//      
//        <div id="tabs-1">
//           <ul>
//               <li class="ui-tabs-nav"><a href="/bbs">论坛新帖</a></li>
//               <li class="ui-tabs-nav"><a href="/blog">最新博文</a></li>
//           </ul>
//           <div class="ui-tabs-panel">
//              <!--这里调用最新论坛文章-->xxxxxxxxxxxxx
//            </div>
//            <div class="ui-tabs-panel">
//              <!--这里调用最新博客文章-->yyyyyyyyyyyyyy
//            </div>
//        </div>
//或
//        <dl id="tabs-2">
//            <dt class="ui-tabs-nav ui-tabs-selected"><a href="/bbs">论坛新帖</a></dt>
//            <dt class="ui-tabs-nav"><a href="/blog">最新博文</a></dt>
//          
//            <dd class="ui-tabs-panel">
//              <!--这里调用最新论坛文章-->xxxxxxxxxxxxx
//            </dd>
//            <dd class="ui-tabs-panel ui-tabs-hide">
//              <!--这里调用最新博客文章-->yyyyyyyyyyyyyy
//            </dd>
//        </div>
//
//js调用
//         var t = new jqTabs("#tabs-1");
//         t.auto();

(function($){

    var jqTabs = window.jqTabs = function( containerId,conf )
    {
        // 主要html部件
        this.container = $(containerId);
        this.tabs      = this.container.find(".ui-tabs-nav");
        this.panels    = this.container.find(".ui-tabs-panel");    

        // 读取配置
        conf = conf || {};
        this.interval = conf.interval || 10000;
        this.event    = conf.event    || 'mouseover';
        this.index    = conf.index    || 0;
        
        // 触发事件
        switch( this.event ){
            case "mouseover" : this.mouseover(); break;
            case "click"     : this.click();     break;
            case "auto"      : this.auto();      break;
        }
        
        // 设置默认显示
        this.switchTab( this.index );
    }

    jqTabs.fn = jqTabs.prototype =
    {
        // mouseover触发
        mouseover : function()
        {
            var that = this;
            this.tabs.mouseover(function(e){
                    that.index = $.inArray( this,that.tabs );
                    that.switchTab( that.index );
            });
        },

        // click触发
        click : function()
        {
            var that = this;
            that.tabs.click(function(e){
                that.index = $.inArray( this,that.tabs );
                that.switchTab( that.index );
            });
        },
        
        // 自动触发
        auto : function()
        {
            var o = this;
            setInterval( function(){ o.auto_thread(); }, o.interval );
        },
        
        // setInterval线程入口
        auto_thread : function()
        {
            this.switchTab( this.index );
            this.index++;
            if( this.tabs.length == this.index ){ this.index = 0;  }
        },
        
        // 切换
        switchTab : function( index )
        {
            if (this.panels.eq(index).is(".ui-tabs-panel")){
                this.tabs.removeClass("ui-tabs-selected").eq(index).addClass("ui-tabs-selected");
                this.panels.addClass("ui-tabs-hide").eq(index).removeClass("ui-tabs-hide");
            }
        }
    };
})( jQuery );


///==================================================================================
/// jqDialog
///==================================================================================
(function($){

    var instances = {};
    //
    // prop 即对话框的属性，有四个值 title,content,width,height
    // 用new 创建的对话框在关闭是会被删除
    // 如果要创建关闭时隐藏的对话框用getInstance方法
    // 
    var jqDialog = window.jqDialog = function(prop)
    {           
        // 设置属性
        prop = prop || {};
        this.title = prop.title || 'Dialog';
        this.content = prop.content || '';
        this.width = prop.width || 'auto';
        this.height = prop.height || 'auto';
        this.isModal = prop.isModal || true;    // 是否模态窗口
        this.masked = prop.masked || null;  // 只有在模态窗口下此属性才生效
        this.resizable = prop.resizable || false;
        this.draggable = prop.draggable || true;
        
        
        var that = this;
        
        // 构建用户界面骨架
        this.wrap = $('<div></div>');
        var head = $('<div></div>');
        var body = $('<div></div>');
        this.wrap.append(head).append(body);
        
        // 填充属性
        var title = $('<span>'+this.title+'</span>');
        var btnClose = $('<span title="关闭">×</span>');
        head.append(title)
                 .append(btnClose);
        
        if(String == this.content.constructor && 0==$(this.content).length)
            body.text(this.content);      //text
        else
            body.append($(this.content)); //dom
        
        // 居中
        this.wrap.css( {position:'absolute'
                ,top:'50%'
                ,left:'50%'
                ,'z-index':'9999'
                ,border:'2px solid #000'
                ,background:'#fff'
                ,'min-width':'200px'
                ,'min-height':'150px'
                ,width:that.width
                ,height:that.height} );
        btnClose.css({'float':'right',border:'1px solid #999','cursor':'pointer',color:'red','font-size':'12pt','font-weight':'bold'});
        head.css({'border-bottom':'1px solid #000',padding:'6px',background:'#999'});
        body.css({background:'#fff','min-height':'100px'});
        
        // 可关闭
        btnClose.click(function(){
            that.close();
        });
        
        if(this.draggable){
            // 可拖拽
            head.mousedown(function(){
            });
            // 可托拽提示
            head.mouseover(function(){
                head.css({cursor:'move'});
            });
        }

        if(this.resizable){
            // 可拉伸
            this.wrap.mousedown(function(ev){
                var target = ev.target;
                if(that.wrap[0].id != target.id)
                    return;
            });
            // 可拉伸提示
            this.wrap.mouseover(function(ev){
                var target = ev.target;
                if(that.wrap[0].id == target.id)
                    that.wrap.css({cursor:'col-resize'});
                else
                    that.wrap.css({cursor:'default'});
            });
        }
    };
    
    // 取得实例,此方法产生的Dialog对象可以反复使用
    jqDialog.getInstance = function(id,prop)
    {
        if(!instances[id]){
            instances[id] = new jqDialog(prop);
            instances[id].wrap[0].id = id;
        }

        return instances[id];
    };
        
    jqDialog.prototype = 
    {
        // 打开对话框
        open : function(parent,callback)
        {   
            var p = $(parent);
            if(this.isModal){
                if(!this.masked)
                    this._maskLayer = p.openMask();
                else
                    this._maskLayer = $(this.masked).openMask();
            }

            if(!this.wrap[0].id || 0==p.find('#'+this.wrap[0].id).length){
                this.wrap.appendTo( p );
                if(callback){
                    callback();
                }
            }

            this.wrap.show();
        },
        // 关闭对话框
        close : function()
        {
            if(!this.wrap[0].id)
                this.wrap.remove();
            else
                this.wrap.hide();
            if(this._maskLayer){ this._maskLayer.closeMask(); }
        }
    };
})(jQuery);

///==================================================================================
/// jqDropDownSelector
///==================================================================================
// 下拉选择框--jqDropDownSelector
//
(function($){
    var jqDropDownSelector = window.jqDropDownSelector = function(ctrlId,panelId,callback){
        this.ctrl = $(ctrlId);
        this.panel = $(panelId);
                    
        if(!this.ctrl[0].id || ''==this.ctrl[0].id)
            this.ctrl[0].id = this.ctrl[0].tagName+$.newId();
        if(!this.panel[0].id || ''==this.panel[0].id)
            this.ctrl[0].id = this.panel[0].tagName+$.newId();

        var that = this;
        this._init();
        
        // 点击下拉出选择面板
        this.ctrl.click(function(e){
            e.stopPropagation();
            that.panel.show('normal').css({left:$(this).position().left+'px'});
            if(callback)
                callback(that);
        });
        
        // 关闭面板方法一,用户点击了非面板和非控制框的其他地方
        $(document).click(function(ev){
            var target = ev.target;
            if(that.ctrl[0].id != target.id && that.panel[0].id != target.id)
                that.closePanel();
        });
        
        // 点击面板是不应该关闭面板
        this.panel.click(function(e){
            e.stopPropagation();
        });
    };
    
    jqDropDownSelector.prototype = {
        _init : function()
        {
            var c = this.ctrl;
            this.panel.css({display:'none',
                            position:'absolute',
                            background:'#fff',
                            border:'1px solid #999'});
            this.ctrl.after(this.panel);
        },
        closePanel : function()
        {
            if ('none'!=this.panel.css('display') )
                this.panel.hide('normal');
        }
    };
    
})(jQuery);


///==================================================================================
/// jqTree
///==================================================================================
//html
//        <!--与此对应的HTML结构是：-->
//      <div id="root">
//          <ul>
//              <li><a href="$">title</a>
//                  <ul>
//                      <li><a href="$">next</a></li>
//                      <li><a href="$">next</a></li>
//                  </ul>
//              </li>
//              <li><a href="$">next</a></li>
//          </ul>
//      </div>


(function($){
    var jqTree = window.jqTree = function( root ){
        $(root).find('ul').css('display','none').each( function(i){
            this.parentNode.onmouseover = function(){
                this.getElementsByTagName('ul')[0].style.display = 'block';
            }
            this.parentNode.onmouseout = function(){
                this.getElementsByTagName('ul')[0].style.display = 'none';
            }
        });
    };
})(jQuery);





// 移动元素，一段神奇的代码
function moveElement(elementID,final_x,final_y,interval) {
    if (!document.getElementById) return false;
    if (!document.getElementById(elementID)) return false;
    var elem = document.getElementById(elementID);
    if (elem.movement) {
        clearTimeout(elem.movement);
    }
    if (!elem.style.left) {
        elem.style.left = "0px";
    }
    if (!elem.style.top) {
        elem.style.top = "0px";
    }
    var xpos = parseInt(elem.style.left);
    var ypos = parseInt(elem.style.top);
    if (xpos == final_x && ypos == final_y) {
        return true;
    }
    if (xpos < final_x) {
        var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
    }
    if (xpos > final_x) {
        var dist = Math.ceil((xpos - final_x)/10);
        xpos = xpos - dist;
    }
    if (ypos < final_y) {
        var dist = Math.ceil((final_y - ypos)/10);
        ypos = ypos + dist;
    }
    if (ypos > final_y) {
        var dist = Math.ceil((ypos - final_y)/10);
        ypos = ypos - dist;
    }
    elem.style.left = xpos + "px";
    elem.style.top = ypos + "px";
    var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
    elem.movement = setTimeout(repeat,interval);
}
